#!/usr/bin/env python
import numpy as np
from MapUtility import MapTools

def loglike(ccube, mcube):
    m1 = MapTools.Open(ccube, verbose=False) # data
    m2 = MapTools.Open(mcube, verbose=False) # model
    mask = m2.map > 0.
    llike = (-m2.map[mask]+m1.map[mask]*np.log(m2.map[mask])).sum()
    return llike

def cli():
    import argparse

    parser = argparse.ArgumentParser(description='Calculate the logLikelihood')
    parser.add_argument("ccube", type=str, help='counts cube')
    parser.add_argument("mcube", type=str, help='model counts ccube')
    args = parser.parse_args()

    llike = loglike(args.ccube, args.mcube)
    print 'logLikelihood = %f' % llike

if __name__ == '__main__': cli()
